package com.elong.android.specialhouse.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;

import com.elong.android.specialhouse.JSONConstants;
import com.elong.android.specialhouse.R;
import com.elong.android.specialhouse.entity.ApartmentKeyword;
import com.elong.android.specialhouse.utils.Utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ApartmentSeachHistroyAdapter extends SpecialSimpleAdapter{

	public ApartmentSeachHistroyAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from,
										int[] to) {
		super(context, data, resource, from, to);
	}

	@SuppressWarnings("unchecked")
	public void setNewData(List data) {
		getData().clear();
		getData().addAll(data);
		notifyDataSetChanged();
	}

	public View getView(final int position, final View convertView, final ViewGroup parent) {
		View v = super.getView(position, convertView, parent);
		v.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				AdapterView adapterView = (AdapterView) parent;
				adapterView.performItemClick(v, position, 0);
			}
		});
		int type = Utils.convertToInt(((HashMap) super.getItem(position)).get(JSONConstants.ATTR_TYPE), 0);
		TextView tv = (TextView) v.findViewById(R.id.keyword_select_item_name_type);
		switch (type) {
		case ApartmentKeyword.TYPE_APARTMENT:
			tv.setText("房源");
			break;
		case ApartmentKeyword.TYPE_DISTRICT:
			tv.setText("行政区");
			break;
		case ApartmentKeyword.TYPE_COMMERCIAL:
			tv.setText("商圈");
			break;
		case ApartmentKeyword.TYPE_UNKNOWN:
			tv.setText("");
			break;
		}
		return v;
	}
}
